package work20241228;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author zdl
 * @date 2024/12/28
 */
class Actor {
    private String name;
    public Actor(String name) { this.name = name; }
    public String getName() { return name; }
    public void setName(String name) { this.name = name; } }

    public class Demo14_16 {
    public static void main(String[] args) {
        //题目14：现在有两个Arraylist集合，分别存储6名男演员和6女演员的名称，要求完成如下的操作：女演员只要姓林的,并且不要第一个
        ArrayList<Actor> list1 = new ArrayList<>();
        list1.add(new Actor("林凡"));
        list1.add(new Actor("林冲"));
        list1.add(new Actor("张三"));
        list1.add(new Actor("牛马"));
        list1.add(new Actor("林四"));
        list1.add(new Actor("林深"));
        ArrayList<Actor> list2 = new ArrayList<>();
        list2.add(new Actor("林琼瑶"));
        list2.add(new Actor("林花花"));
        list2.add(new Actor("林舒舒"));
        list2.add(new Actor("林悄悄"));
        List<Actor> collect1 = list2.stream()
                .filter(s -> s.getName().startsWith("林"))
                .skip(1)
                .collect(Collectors.toList());
        collect1.stream().forEach(s -> System.out.println(s.getName()));


        //题目15：把过滤后的男演员女演员合并
        List<Actor> collect = Stream.concat(list1.stream(), list2.stream()).filter(s -> s.getName().startsWith("林")).collect(Collectors.toList());

        //题目16：把上一步的操作后的元素作为构造方法的参数创建演员Actor对象,并遍历
        for (Actor actor : collect) {
            String name = actor.getName();
            System.out.println(name);
        }


    }
}
